/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.devel.designpatterns.singleton;

import com.devel.designpatterns.composite.Component;
import com.devel.designpatterns.composite.Composite;
import com.devel.designpatterns.composite.Leaf;

/**
 *
 * @author wm.devel
 */
public class CompositeSingleton {
    
    private static CompositeSingleton INSTANCE;
    private Component root;
    
    private CompositeSingleton() {
        root = new Composite();
        root.add(new Leaf("A"));
        root.add(new Leaf("B"));
        Component branch = new Composite();
        root.add(branch);
        branch.add(new Leaf("dd"));
        branch.add(new Leaf("ee"));
        root.add(new Leaf("C"));
    }
    
    public Component getRoot() {
        return root;
    }
    
    public static CompositeSingleton instance() {
        if (INSTANCE == null)
            INSTANCE = new CompositeSingleton();
        return INSTANCE;
    }
}
